import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true, meta: { title: '绑定' }},
  { path: '/register', component: _import('login/register'), hidden: true, meta: { title: '立即注册' }},
  { path: '/forget', component: _import('login/forget'), hidden: true, meta: { title: '忘记密码' }},
  {
    path: '',
    component: Layout,
    redirect: 'home/index',
    children: [{
      path: 'home',
      component: _import('home/index'),
      redirect: 'home/index',
      children: [{
        path: 'index',
        component: _import('home/index'),
        name: 'home-index',
        meta: { title: '首页', icon: 'home', noCache: true, lessLogin: true }
      }]
    }, {
      path: 'newHouse',
      component: _import('home/home'),
      name: 'newHouse',
      meta: { title: '新房', icon: 'home', noCache: true }
    }, {
      path: 'secondHand',
      component: _import('home/home'),
      name: 'secondHand',
      meta: { title: '二手房', icon: 'home', noCache: true }
    }, {
      path: 'rentHouse',
      component: _import('home/home'),
      name: 'rentHouse',
      meta: { title: '租房', icon: 'home', noCache: true }
    }, {
      path: 'news',
      component: _import('home/news'),
      name: 'news',
      meta: { title: '资讯', icon: 'home', noCache: true }
    }, {
      path: '/mine',
      component: _import('mine/mine'),
      name: 'mine-index',
      meta: { title: '个人中心', icon: 'home', noCache: true }
    }]
  },
  {
    path: '/detail',
    component: _import('detail/layout'),
    children: [{
      path: 'index',
      component: _import('detail/index'),
      name: 'detail-index',
      meta: { title: '房源详情', icon: 'home', noCache: true }
    }, {
      path: 'appoint',
      component: _import('detail/appoint'),
      name: 'detail-appoint',
      meta: { title: '预约看房', icon: 'home', noCache: true }
    }, {
      path: 'report',
      component: _import('detail/report'),
      name: 'detail-report',
      meta: { title: '报备看房', icon: 'home', noCache: true }
    }, {
      path: 'visit',
      component: _import('detail/visit'),
      name: 'detail-visit',
      meta: { title: '带看', icon: 'home', noCache: true }
    }, {
      path: 'apply',
      component: _import('detail/apply'),
      name: 'detail-apply',
      meta: { title: '申请入驻', icon: 'home', noCache: true }
    }, {
      path: 'order',
      component: _import('detail/order'),
      name: 'detail-order',
      meta: { title: '成交订单', icon: 'home', noCache: true }
    }, {
      path: 'news-detail',
      component: _import('detail/news-detail'),
      name: 'news-detail',
      meta: { title: '资讯详情', icon: 'home', noCache: true }
    }]
  },
  {
    path: '/search',
    component: _import('search/search'),
    name: 'search',
    meta: { title: '搜索', icon: 'home', noCache: true }
  },
  {
    path: '/area',
    component: _import('search/area'),
    name: 'area',
    meta: { title: '地区', icon: 'home', noCache: true }
  },
  {
    path: '/mine',
    component: _import('mine/index'),
    children: [{
      path: 'index',
      component: _import('mine/setting'),
      name: 'mine-setting',
      meta: { title: '设置', icon: 'home', noCache: true }
    }, {
      path: 'appoint',
      component: _import('mine/appoint'),
      name: 'mine-appoint',
      meta: { title: '我的预约', icon: 'home', noCache: true }
    }, {
      path: 'report',
      component: _import('mine/report'),
      name: 'mine-report',
      meta: { title: '报备记录', icon: 'home', noCache: true }
    }, {
      path: 'visit',
      component: _import('mine/visit'),
      name: 'mine-visit',
      meta: { title: '带看记录', icon: 'home', noCache: true }
    }, {
      path: 'team',
      component: _import('mine/team'),
      name: 'mine-team',
      meta: { title: '团队记录', icon: 'home', noCache: true }
    }, {
      path: 'moneyEdit',
      component: _import('mine/moneyEdit'),
      name: 'mine-moneyEdit',
      meta: { title: '账户充值', icon: 'home', noCache: true }
    }, {
      path: 'userInfo',
      component: _import('mine/userInfo'),
      name: 'mine-userInfo',
      meta: { title: '个人信息', icon: 'home', noCache: true }
    }, {
      path: 'scan',
      component: _import('mine/scan'),
      name: 'mine-scan',
      meta: { title: '我的推荐码', icon: 'home', noCache: true }
    }, {
      path: 'collect',
      component: _import('mine/collect'),
      name: 'mine-collect',
      meta: { title: '我的收藏', icon: 'home', noCache: true }
    }, {
      path: 'history',
      component: _import('mine/history'),
      name: 'money-history',
      meta: { title: '记录', icon: 'home', noCache: true, lessLogin: true }
    }]
  }
]
const router = new Router({
  // mode: 'history', // 后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
export default router
router.afterEach((to, from) => {
  if (from && to) {
    if (to.meta.title) {
      document.title = to.meta.title
    }
  }
})
export const asyncRouterMap = [
]
